﻿Public Class BESort
  Dim _strOrderBy As String

  Sub New()
    _strOrderBy = ""
  End Sub

  Sub New(ByVal strExpressao As String, ByVal strDirecao As String)
    _strOrderBy = ""
    AdicionarCondicaoOrderBy(strExpressao, strDirecao)
  End Sub

  Public Property OrderBy() As String
    Get
      Return IIf(_strOrderBy.Length > 0, " ORDER BY " & _strOrderBy, "")
    End Get
    Set(ByVal value As String)
      _strOrderBy = value
    End Set
  End Property

  Public Sub AdicionarCondicaoOrderBy(ByVal strExpressao As String, ByVal strDirecao As String)
    If (strExpressao IsNot Nothing AndAlso strExpressao.Length > 0 AndAlso _
        strDirecao IsNot Nothing AndAlso strDirecao.Length > 0) Then
      _strOrderBy &= IIf(_strOrderBy.Length > 0, ", ", "") & strExpressao & " " & strDirecao
    End If
  End Sub

End Class
